<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<style type="text/css">
			html,body { background-color:#F7F8FA; }
			.center ul{ margin-top: 10px; background-color: #fff; overflow: hidden;}
			.center .top a{ padding: 15px;}
			.center .top .m_cell_hd img{ width: 45px; height: 45px; border-radius: 5px; margin-right: 10px;}
			.center .top h4{ display:block; font-size: 15px; font-weight: 600; color: #515156; line-height: 20px;}
			.center .top p{ font-size: 12px; color: #9F9F9F; line-height: 20px;}
			.center .top .m_cell_ft img{ width: 6px;}
			.center .list li{ position: relative;padding: 13px;}
			.center .list li::after{ position: absolute; content: ""; left: 40px; right: 0; bottom: 0; border-bottom: 1px #d4d4d4 solid; transform: scaleY(0.5);}
			.center .list .m_cell_ft img{ width: 6px;}
			.center .list .m_cell_hd img{ width: 20px; margin-right: 10px;}
			.center .list h4{ display:block; font-size: 15px; color: #474747; font-weight: 400;}
			.center .list p{ font-size:14px;padding-right:10px; color: #999;}
			.display-none { display:none; }
		</style>
	</head>
	<body>
		<div class="center">
			<ul class="top">
				<a href="javascript:;" tapmode="lipress" onclick="openNavWin('#fff','userinfo_win','userinfo_frm.html','个人信息',false,false,true,[],{});">
					<div class="m_cell_hd"><img data-url="" src="../../image/defaultimg.png" id="avatar" /></div>
					<div class="m_cell_hd m_cell_primary">
						<h4 id="nickname">---</h4>
						<p id="companyauth"></p>
					</div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</a>
			</ul>
			<ul class="list">
				<li class="mylist" attr-name="mybill" tapmode="lipress">
					<div class="m_cell_hd"><img src="../../image/img_04.png" alt="" /></div>
					<div class="m_cell_hd m_cell_primary"><h4>我的运单</h4></div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</li>
				<li class="mylist" attr-name="mygoods" tapmode="lipress">
					<div class="m_cell_hd"><img src="../../image/img_05.png" alt="" /></div>
					<div class="m_cell_hd m_cell_primary"><h4>我发布的货源</h4></div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</li>
				<li class="mylist" attr-name="mymoney" tapmode="lipress">
					<div class="m_cell_hd"><img src="../../image/img_06.png" alt="" /></div>
					<div class="m_cell_hd m_cell_primary"><h4>我的钱包</h4></div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</li>
				<li class="mylist" attr-name="myauth" tapmode="lipress">
					<div class="m_cell_hd"><img src="../../image/img_07.png" alt="" /></div>
					<div class="m_cell_hd m_cell_primary"><h4>身份认证</h4></div>
					<div class="m_cell_ft"><p id="userstatus"></p></div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</li>
				<li class="mylist1" attr-name="" onclick="meiqia()" tapmode="lipress">
					<div class="m_cell_hd"><img src="../../image/img_08.png" alt="" /></div>
					<div class="m_cell_hd m_cell_primary"><h4>在线客服</h4></div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</li>
				<li class="mylist1" id="baoxianurl" attr-name="" onclick="openurl()" tapmode="lipress">
					<div class="m_cell_hd"><img src="../../image/img_09.png" alt="" /></div>
					<div class="m_cell_hd m_cell_primary"><h4>推荐保险</h4></div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</li>
				<li class="mylist" attr-name="share" tapmode="lipress">
					<div class="m_cell_hd"><img src="../../image/img_11.png" alt="" /></div>
					<div class="m_cell_hd m_cell_primary"><h4>分享给朋友</h4></div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</li>
				<li class="mylist" attr-name="setting" tapmode="lipress">
					<div class="m_cell_hd"><img src="../../image/img_10.png" alt="" /></div>
					<div class="m_cell_hd m_cell_primary"><h4>设置</h4></div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</li>
				<!-- <li class="mylist1" attr-name="" onclick="sendPosition()" tapmode="lipress"> -->
					<!-- <div class="m_cell_hd"><img src="../../image/img_10.png" alt="" /></div> -->
					<!-- <div class="m_cell_hd m_cell_primary"><h4>测试</h4></div> -->
					<!-- <div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div> -->
				<!-- </li> -->
			</ul>
		</div>

	</body>
	<script type="text/javascript" src="../../script/api.js" ></script>
	<script type="text/javascript" src="../../script/app.js" ></script>
	<script type="text/javascript">
		var companytel = '';
		apiready = function() {
			console.log(api.frameHeight);
			var lists = $api.domAll('.mylist');
			for (var i = 0; i < lists.length; i++) {
				lists[i].onclick = function() {
					var winname = $api.attr(this,'attr-name');
					var param = {};
					var wintitle = $api.text($api.eq(this, 2)).trim();
					if(winname == 'mybill' || winname == 'mygoods' || winname == 'mygoodstest')
					{
						opWin(winname,winname+'_win.html',true,param,false);
					}
					else
					{
						openNavWin('#ddd',winname+'_win',winname+'_frm.html',wintitle,false,false,true,[],{});
					}
				}
			}

			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret && ret.value)
				{
					var userinfo = JSON.parse(ret.value);
					updateuser(userinfo);
					
				}
			});
			api.addEventListener({
				name : 'updateuser'
			}, function(ret, err) {
				updateuser(ret.value.userjson);
				
			});
			
			api.addEventListener({
				name : 'refreshsysmsg'
			}, function(ret, err) {
				getJsonFromAPI();
				
			});
		}
		function sendPosition() {
			var rong = api.require('rongCloud2');
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret && ret.value)
				{
					var userinfo = JSON.parse(ret.value);
					rong.sendLocationMessage({
						conversationType : 'PRIVATE',
						targetId : '13653852083',
						latitude : 106.571733,
						longitude: 29.573898,
						poi: '重庆市江北区江北城街道江北城大街东方国际广场',
						imagePath: 'fs://qrcode/qrcode'+userinfo.uid+'.png',
						extra : ''
					}, function(ret, err) {
						alert(JSON.stringify(ret));
						alert(JSON.stringify(err));
					});
				}
			});
			
		}
		function getJsonFromAPI() {
			//从接口获取查询数据
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret.value) {
					var userinfo = JSON.parse(ret.value);
					api.ajax({
						url: ApiUrl + '/v1/userinfo',
						method: 'get',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						}
					}, function(ret, err) {
						
						if (ret) {
							userinfo.avatar = ret.avatar;
							api.setPrefs({
								key: 'user_info',
								value: userinfo
							}, function(ret, err) {
								updateuser(userinfo);
							});
						} else {
							if(err.statusCode==402)
							{
								Relogin();
							}
							else
							{
								toast('网络异常');
								console.log(JSON.stringify(err));
							}
						}
					});
				}
			});
		}
		function meiqia() {
			//创建美洽
			var mq = api.require('meiQia');
			var titleColor = {
				color: "#000000"
			};
			mq.setTitleColor(titleColor);
			//mq.configChat({backConfig:{img:'widget://image/backa.png',w:25,h:25}});
			mq.show();
		}
		function openurl() {
			opWin('openurl_win','openurl_win.html',true,{
				title: '推荐保险',
				url: 'https://m.163.com'
			},false);
		}
		function updateuser(userjson) {
			if(userjson.ishidden == 1) {
				$api.addCls($api.byId('baoxianurl'),'display-none');
			}
			//alert($api.getStorage('noreadsysmsg'));
			//设置头像昵称等
			//var user = JSON.parse(userjson);
			var avatar = '../../image/defaultimg.png';
			if(userjson.access_token)
			{
				if(userjson.avatar!='')
				{
					avatar = userjson.avatar;
					$api.attr($api.byId('avatar'),'data-url',avatar);
					fnLoadImage($api.byId('avatar'));
				}
				else
				{
					avatar = '../../image/defaultimg.png';
					$api.attr($api.byId('avatar'),'data-url',"");
					$api.attr($api.byId('avatar'),'src',avatar);
				}
				nickname = userjson.realname;
			}
			else
			{
				avatar = '../../image/defaultimg.png';
				nickname = '未登录';
			}
			var companyauth = '车主认证';
			if(userjson.usertype == 2)
			{
				companyauth = '企业认证';
			}
			if(userjson.status == 0)
			{
				//companyauth += '中';
				$api.text($api.byId('userstatus'),'审核中');
			}
			else
			{
				$api.text($api.byId('userstatus'),'');
			}
			$api.text($api.byId('companyauth'),companyauth);
			//$api.attr($api.byId('avatar'),'src',avatar);
			$api.text($api.byId('nickname'),nickname);

		}
		function fnLoadImage(obj) {
			var dataUrl = $api.attr(obj, 'data-url');
			if(dataUrl!=''){
				api.imageCache({
					url: dataUrl
				}, function(ret, err) {
					if(ret && ret.status == true){
						obj.src = ret.url;
					}
				});
			}
		}
	</script>
</html>